package com.sneakxy.mybase4j.platform.service;

import com.alibaba.dubbo.config.annotation.Reference;

import com.sneakxy.mybase4j.base.service.BaseService;

import com.sneakxy.mybase4j.platform.beans.Menu;

import com.sneakxy.mybase4j.platform.provider.IMenuProvider;

import com.sneakxy.mybase4j.platform.service.IMenuService;
import com.sneakxy.mybatis.commons.repository.query.domain.CriteriaBuilder;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import org.springframework.stereotype.Service;

/**
 * 
 * @author 潜行的青衣
 * @see
 */
@Service
public class MenuService extends BaseService<Menu, String, IMenuProvider> implements IMenuService {

	@Reference(version = "1.0.0")
	@Autowired(required = false)
	@Qualifier("menuProvider")
	private IMenuProvider provider;

	@Override
	public IMenuProvider getProvider() {
		return this.provider;
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IMenuService#findByAccountId(java.lang.String)
	 */
	@Override
	public List<Menu> findByAccountId(String account_id, String type) {
		return this.getProvider().findByAccountId(account_id, type);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IMenuService#findTreeByType(java.lang.String)
	 */
	@Override
	public List<Menu> findTreeByType(String type) {
		return this.getProvider().findTreeByType(type);
	}

	/* (non-Javadoc)
	 * @see com.sneakxy.mybase4j.platform.service.IMenuService#hasChildren(java.lang.String)
	 */
	@Override
	public boolean hasChildren(String id) {
		CriteriaBuilder<Menu> builder = new CriteriaBuilder<Menu>(Menu.class);
		builder.andEq("type", id);
		return this.getProvider().count(builder.build()) > 0;
	}

}
